<template>
  <div class="login">
    <div>
      <div class="welcome">Welcome</div>
      <div class="form">
        <div class="form_item">
          <div class="label"><i class="el-icon-user"></i></div>
          <div class="value">
            <input v-model="username" placeholder="account" type="text">
          </div>
        </div>
        <div class="form_item">
          <div class="label"><i class="el-icon-lock"></i></div>
          <div class="value">
            <input v-model="password" placeholder="password" type="password">
          </div>
        </div>
        <div class="Login">
          <button @click="submit" style="margin-right:5px;">Login</button>
          <button @click="$router.push('/register')" >register</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: 'LoginView',
  data() {
    return {
      username: '',
      password: '',
    }
  },

  created() {
    
  },

  methods: {

    // 登录
    async submit() {
      const formdata = {
        username: this.username,
        password: this.password,
      }
      const res = await this.$http.post("/user/login", formdata)
      console.log("res",res)
      if (res.data.state == true) {
        localStorage.setItem("user_id",res.data.user_id);
        localStorage.setItem("username",res.data.username);
        localStorage.setItem("password",this.password);
        console.log("local",localStorage)
        this.$message({
          message: '登录成功！',
          type: 'success'
        });
        this.$router.push('/index/home')
        
      }else {
        this.$message({
          message: res.data.message||'登录失败！',
          type: 'warning'
        });
      }

    },

  }
}
</script>

<style lang="less" scoped>
.login {
  height: 100%;
  background-size: cover;
  background-size: 100% 100%;
  background-image: url(../static/background_image/1684459621948.jpg);
  display: flex;
  justify-content: center;
  .welcome {
    background: rgba(255, 255, 255, 0.3);
    margin-top: 10px;
    width: 481px;
    height: 88px;
    border-radius: 12px;
    line-height: 88px;
    font-weight: 400;
    font-size: 96px;
    text-align: center;
    color: #FFFFFF;
  }
  .form {
    padding-top: 60px;
    .form_item {
      padding: 25px 0;
      display: flex;
      align-items: center;
      justify-content: center;
      .label {
        margin-right: 40px;
        font-size: 40px;
      }
      .value {
        width: 280px;
        height: 44px;
        background-color: rgba(255, 255, 255, 0.3);
        border-radius: 12px;
        input {
          width: 100%;
          height: 100%;
          background: none;
          border: none;
          color: #fff;
          text-align: center;
          font-size: 20px;
        }
      }
      .submit {
        width: 280px;
        display: flex;
        justify-content: space-between;
        button {
          width: 107px;
          height: 44px;
          background-color: rgba(255, 255, 255, 0.3);
          border-radius: 12px;
          border: none;
          color: #FFFFFF;
          font-size: 20px;
        }
      }
    }
    .Login {
      padding-top: 10px;
      text-align: center;
      padding-left:15%;
      button {
        width: 107px;
        height: 44px;
        background-color: rgba(255, 255, 255, 0.3);
        border-radius: 12px;
        border: none;
        color: #FFFFFF;
        font-size: 20px;
      }
    }
   // .login:{}
  }
}
input::-webkit-input-placeholder{
  color:#fff;
  font-size: 22px;
  line-height: 44px;
}

input::-moz-placeholder{   /* Mozilla Firefox 19+ */
  color:#fff;
  font-size: 22px;
  line-height: 44px;
}

input:-moz-placeholder{    /* Mozilla Firefox 4 to 18 */
  color:#fff;
  font-size: 22px;
  line-height: 44px;
}

input:-ms-input-placeholder{  /* Internet Explorer 10-11 */
  color:#fff;
  font-size: 22px;
  line-height: 44px;
}
</style>